﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using JXT.PrimaryKey.Batman.Core.Infrastructure;

namespace JXT.PrimaryKey.Batman.Core.Container.Unity
{
    /// <summary>
    /// 可删除对象管理器
    /// </summary>
    public class CanRemovePerThreadLifetimeManager : LifetimeManager
    {
        private readonly string _key = Guid.NewGuid().ToString();
        private ThreadObjectContainer _container = new ThreadObjectContainer();

        public override object GetValue()
        {
            object result;
            _container.Items.TryGetValue(_key, out result);
            return result;
        }

        public override void RemoveValue()
        {
            _container.Items.Remove(_key);
        }

        public override void SetValue(object newValue)
        {
            _container.Items[_key] = newValue;
        }

    }
}
